using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the DDLEvent class.
	/// </summary>
	[Serializable]
	public partial class DDLEventCollection : ActiveList<DDLEvent, DDLEventCollection> 
	{	   
		public DDLEventCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the DDLEvents table.
	/// </summary>
	[Serializable]
	public partial class DDLEvent : ActiveRecord<DDLEvent>
	{
		#region .ctors and Default Settings
		
		public DDLEvent()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public DDLEvent(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public DDLEvent(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public DDLEvent(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("DDLEvents", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "Id";
				colvarId.DataType = DbType.Int64;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarEventDate = new TableSchema.TableColumn(schema);
				colvarEventDate.ColumnName = "EventDate";
				colvarEventDate.DataType = DbType.DateTime;
				colvarEventDate.MaxLength = 0;
				colvarEventDate.AutoIncrement = false;
				colvarEventDate.IsNullable = false;
				colvarEventDate.IsPrimaryKey = false;
				colvarEventDate.IsForeignKey = false;
				colvarEventDate.IsReadOnly = false;
				
						colvarEventDate.DefaultSetting = @"(getdate())";
				colvarEventDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventDate);
				
				TableSchema.TableColumn colvarEventType = new TableSchema.TableColumn(schema);
				colvarEventType.ColumnName = "EventType";
				colvarEventType.DataType = DbType.String;
				colvarEventType.MaxLength = 64;
				colvarEventType.AutoIncrement = false;
				colvarEventType.IsNullable = true;
				colvarEventType.IsPrimaryKey = false;
				colvarEventType.IsForeignKey = false;
				colvarEventType.IsReadOnly = false;
				colvarEventType.DefaultSetting = @"";
				colvarEventType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventType);
				
				TableSchema.TableColumn colvarEventDDL = new TableSchema.TableColumn(schema);
				colvarEventDDL.ColumnName = "EventDDL";
				colvarEventDDL.DataType = DbType.String;
				colvarEventDDL.MaxLength = -1;
				colvarEventDDL.AutoIncrement = false;
				colvarEventDDL.IsNullable = true;
				colvarEventDDL.IsPrimaryKey = false;
				colvarEventDDL.IsForeignKey = false;
				colvarEventDDL.IsReadOnly = false;
				colvarEventDDL.DefaultSetting = @"";
				colvarEventDDL.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventDDL);
				
				TableSchema.TableColumn colvarEventXML = new TableSchema.TableColumn(schema);
				colvarEventXML.ColumnName = "EventXML";
				colvarEventXML.DataType = DbType.String;
				colvarEventXML.MaxLength = -1;
				colvarEventXML.AutoIncrement = false;
				colvarEventXML.IsNullable = true;
				colvarEventXML.IsPrimaryKey = false;
				colvarEventXML.IsForeignKey = false;
				colvarEventXML.IsReadOnly = false;
				colvarEventXML.DefaultSetting = @"";
				colvarEventXML.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventXML);
				
				TableSchema.TableColumn colvarDatabaseName = new TableSchema.TableColumn(schema);
				colvarDatabaseName.ColumnName = "DatabaseName";
				colvarDatabaseName.DataType = DbType.String;
				colvarDatabaseName.MaxLength = 255;
				colvarDatabaseName.AutoIncrement = false;
				colvarDatabaseName.IsNullable = true;
				colvarDatabaseName.IsPrimaryKey = false;
				colvarDatabaseName.IsForeignKey = false;
				colvarDatabaseName.IsReadOnly = false;
				colvarDatabaseName.DefaultSetting = @"";
				colvarDatabaseName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDatabaseName);
				
				TableSchema.TableColumn colvarSchemaName = new TableSchema.TableColumn(schema);
				colvarSchemaName.ColumnName = "SchemaName";
				colvarSchemaName.DataType = DbType.String;
				colvarSchemaName.MaxLength = 255;
				colvarSchemaName.AutoIncrement = false;
				colvarSchemaName.IsNullable = true;
				colvarSchemaName.IsPrimaryKey = false;
				colvarSchemaName.IsForeignKey = false;
				colvarSchemaName.IsReadOnly = false;
				colvarSchemaName.DefaultSetting = @"";
				colvarSchemaName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSchemaName);
				
				TableSchema.TableColumn colvarObjectName = new TableSchema.TableColumn(schema);
				colvarObjectName.ColumnName = "ObjectName";
				colvarObjectName.DataType = DbType.String;
				colvarObjectName.MaxLength = 255;
				colvarObjectName.AutoIncrement = false;
				colvarObjectName.IsNullable = true;
				colvarObjectName.IsPrimaryKey = false;
				colvarObjectName.IsForeignKey = false;
				colvarObjectName.IsReadOnly = false;
				colvarObjectName.DefaultSetting = @"";
				colvarObjectName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarObjectName);
				
				TableSchema.TableColumn colvarHostName = new TableSchema.TableColumn(schema);
				colvarHostName.ColumnName = "HostName";
				colvarHostName.DataType = DbType.String;
				colvarHostName.MaxLength = 64;
				colvarHostName.AutoIncrement = false;
				colvarHostName.IsNullable = true;
				colvarHostName.IsPrimaryKey = false;
				colvarHostName.IsForeignKey = false;
				colvarHostName.IsReadOnly = false;
				colvarHostName.DefaultSetting = @"";
				colvarHostName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHostName);
				
				TableSchema.TableColumn colvarIPAddress = new TableSchema.TableColumn(schema);
				colvarIPAddress.ColumnName = "IPAddress";
				colvarIPAddress.DataType = DbType.String;
				colvarIPAddress.MaxLength = 32;
				colvarIPAddress.AutoIncrement = false;
				colvarIPAddress.IsNullable = true;
				colvarIPAddress.IsPrimaryKey = false;
				colvarIPAddress.IsForeignKey = false;
				colvarIPAddress.IsReadOnly = false;
				colvarIPAddress.DefaultSetting = @"";
				colvarIPAddress.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIPAddress);
				
				TableSchema.TableColumn colvarProgramName = new TableSchema.TableColumn(schema);
				colvarProgramName.ColumnName = "ProgramName";
				colvarProgramName.DataType = DbType.String;
				colvarProgramName.MaxLength = 255;
				colvarProgramName.AutoIncrement = false;
				colvarProgramName.IsNullable = true;
				colvarProgramName.IsPrimaryKey = false;
				colvarProgramName.IsForeignKey = false;
				colvarProgramName.IsReadOnly = false;
				colvarProgramName.DefaultSetting = @"";
				colvarProgramName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarProgramName);
				
				TableSchema.TableColumn colvarLoginName = new TableSchema.TableColumn(schema);
				colvarLoginName.ColumnName = "LoginName";
				colvarLoginName.DataType = DbType.String;
				colvarLoginName.MaxLength = 255;
				colvarLoginName.AutoIncrement = false;
				colvarLoginName.IsNullable = true;
				colvarLoginName.IsPrimaryKey = false;
				colvarLoginName.IsForeignKey = false;
				colvarLoginName.IsReadOnly = false;
				colvarLoginName.DefaultSetting = @"";
				colvarLoginName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLoginName);
				
				TableSchema.TableColumn colvarMovedtoLive = new TableSchema.TableColumn(schema);
				colvarMovedtoLive.ColumnName = "MovedtoLive";
				colvarMovedtoLive.DataType = DbType.Boolean;
				colvarMovedtoLive.MaxLength = 0;
				colvarMovedtoLive.AutoIncrement = false;
				colvarMovedtoLive.IsNullable = false;
				colvarMovedtoLive.IsPrimaryKey = false;
				colvarMovedtoLive.IsForeignKey = false;
				colvarMovedtoLive.IsReadOnly = false;
				
						colvarMovedtoLive.DefaultSetting = @"((0))";
				colvarMovedtoLive.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMovedtoLive);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("DDLEvents",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("Id")]
		public long Id 
		{
			get { return GetColumnValue<long>("Id"); }

			set { SetColumnValue("Id", value); }

		}

		  
		[XmlAttribute("EventDate")]
		public DateTime EventDate 
		{
			get { return GetColumnValue<DateTime>("EventDate"); }

			set { SetColumnValue("EventDate", value); }

		}

		  
		[XmlAttribute("EventType")]
		public string EventType 
		{
			get { return GetColumnValue<string>("EventType"); }

			set { SetColumnValue("EventType", value); }

		}

		  
		[XmlAttribute("EventDDL")]
		public string EventDDL 
		{
			get { return GetColumnValue<string>("EventDDL"); }

			set { SetColumnValue("EventDDL", value); }

		}

		  
		[XmlAttribute("EventXML")]
		public string EventXML 
		{
			get { return GetColumnValue<string>("EventXML"); }

			set { SetColumnValue("EventXML", value); }

		}

		  
		[XmlAttribute("DatabaseName")]
		public string DatabaseName 
		{
			get { return GetColumnValue<string>("DatabaseName"); }

			set { SetColumnValue("DatabaseName", value); }

		}

		  
		[XmlAttribute("SchemaName")]
		public string SchemaName 
		{
			get { return GetColumnValue<string>("SchemaName"); }

			set { SetColumnValue("SchemaName", value); }

		}

		  
		[XmlAttribute("ObjectName")]
		public string ObjectName 
		{
			get { return GetColumnValue<string>("ObjectName"); }

			set { SetColumnValue("ObjectName", value); }

		}

		  
		[XmlAttribute("HostName")]
		public string HostName 
		{
			get { return GetColumnValue<string>("HostName"); }

			set { SetColumnValue("HostName", value); }

		}

		  
		[XmlAttribute("IPAddress")]
		public string IPAddress 
		{
			get { return GetColumnValue<string>("IPAddress"); }

			set { SetColumnValue("IPAddress", value); }

		}

		  
		[XmlAttribute("ProgramName")]
		public string ProgramName 
		{
			get { return GetColumnValue<string>("ProgramName"); }

			set { SetColumnValue("ProgramName", value); }

		}

		  
		[XmlAttribute("LoginName")]
		public string LoginName 
		{
			get { return GetColumnValue<string>("LoginName"); }

			set { SetColumnValue("LoginName", value); }

		}

		  
		[XmlAttribute("MovedtoLive")]
		public bool MovedtoLive 
		{
			get { return GetColumnValue<bool>("MovedtoLive"); }

			set { SetColumnValue("MovedtoLive", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(DateTime varEventDate,string varEventType,string varEventDDL,string varEventXML,string varDatabaseName,string varSchemaName,string varObjectName,string varHostName,string varIPAddress,string varProgramName,string varLoginName,bool varMovedtoLive)
		{
			DDLEvent item = new DDLEvent();
			
			item.EventDate = varEventDate;
			
			item.EventType = varEventType;
			
			item.EventDDL = varEventDDL;
			
			item.EventXML = varEventXML;
			
			item.DatabaseName = varDatabaseName;
			
			item.SchemaName = varSchemaName;
			
			item.ObjectName = varObjectName;
			
			item.HostName = varHostName;
			
			item.IPAddress = varIPAddress;
			
			item.ProgramName = varProgramName;
			
			item.LoginName = varLoginName;
			
			item.MovedtoLive = varMovedtoLive;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(long varId,DateTime varEventDate,string varEventType,string varEventDDL,string varEventXML,string varDatabaseName,string varSchemaName,string varObjectName,string varHostName,string varIPAddress,string varProgramName,string varLoginName,bool varMovedtoLive)
		{
			DDLEvent item = new DDLEvent();
			
				item.Id = varId;
				
				item.EventDate = varEventDate;
				
				item.EventType = varEventType;
				
				item.EventDDL = varEventDDL;
				
				item.EventXML = varEventXML;
				
				item.DatabaseName = varDatabaseName;
				
				item.SchemaName = varSchemaName;
				
				item.ObjectName = varObjectName;
				
				item.HostName = varHostName;
				
				item.IPAddress = varIPAddress;
				
				item.ProgramName = varProgramName;
				
				item.LoginName = varLoginName;
				
				item.MovedtoLive = varMovedtoLive;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"Id";
			 public static string EventDate = @"EventDate";
			 public static string EventType = @"EventType";
			 public static string EventDDL = @"EventDDL";
			 public static string EventXML = @"EventXML";
			 public static string DatabaseName = @"DatabaseName";
			 public static string SchemaName = @"SchemaName";
			 public static string ObjectName = @"ObjectName";
			 public static string HostName = @"HostName";
			 public static string IPAddress = @"IPAddress";
			 public static string ProgramName = @"ProgramName";
			 public static string LoginName = @"LoginName";
			 public static string MovedtoLive = @"MovedtoLive";
						
		}

		#endregion
	}

}

